'''
Author: devis.dong
Email: devis.dong@gmail.com
Date: 2022-10-21 18:48:49
LastEditTime: 2022-11-11 13:19:39
LastEditors: devis.dong
FilePath: \retrieval-3d\mydefine.py
Description:
'''
#命令字段定义
RESPONSE_ERROR          = 0x11111111 # 发生错误
# REQUEST_GETFEATURE      = 0x00000001 # 计算特征
# RESPONSE_GETFEATURE     = 0x10000001 # 计算特征
REQUEST_SEARCHMODEL     = 0x00000002 # 搜索模型
RESPONSE_SEARCHMODEL    = 0x10000002 # 搜索模型
REQUEST_UPLOADMODEL     = 0x00000003 # 上传模型(计算特征值)
RESPONSE_UPLOADMODEL    = 0x10000003 # 上传模型(计算特征值)
REQUEST_SEARCHLABEL     = 0x00000004 # 搜索模型标签
RESPONSE_SEARCHLABEL    = 0x10000004 # 搜索模型标签
REQUEST_SEARCHTYPE      = 0x00000005 # 搜索模型标签
RESPONSE_SEARCHTYPE     = 0x10000005 # 搜索模型标签

REQUEST_TYPEINDEX      = 0x00000006 # 类型索引
RESPONSE_TYPEINDEX     = 0x10000006 # 类型索引
REQUEST_LABELINDEX      = 0x00000007 # 标签索引
RESPONSE_LABELINDEX     = 0x10000007 # 标签索引
REQUEST_MODELINDEX      = 0x00000008 # 内容索引
RESPONSE_MODELINDEX     = 0x10000008 # 内容索引

REQUEST_PULLTYPE        = 0x00000009 # 请求拉取类型
RESPONSE_PULLTYPE       = 0x10000009 # 拉取类型
REQUEST_PULLTAGS        = 0x0000000A # 请求拉取标签
RESPONSE_PULLTAGS       = 0x1000000A # 拉取标签

REQUEST_PUSHTYPE        = 0x0000000B # 请求推送类型
RESPONSE_PUSHTYPE       = 0x1000000B # 推送类型
REQUEST_PUSHTAGS        = 0x0000000C # 请求推送标签
RESPONSE_PUSHTAGS       = 0x1000000C # 推送标签

REQUEST_UPLOADMODEL_SIMPLE  = 0x0000000D # 上传模型(不计算特征值)
RESPONSE_UPLOADMODEL_SIMPLE = 0x1000000D # 上传模型(不计算特征值)

REQUEST_SHOWTABLE     = 0x0000000E # 请求显示模型数据表
RESPONSE_SHOWTABLE    = 0x1000000E # 显示模型数据表

REQUEST_INDEXPULL     = 0x0000000F # 请求拉取索引
RESPONSE_INDEXPULL    = 0x1000000F # 拉取索引
REQUEST_INDEXPUSH     = 0x00000010 # 请求推送索引
RESPONSE_INDEXPUSH    = 0x10000010 # 推送索引

REQUEST_VERSIONCREATE          = 0x00000011 # 版本库创建
RESPONSE_VERSIONCREATE         = 0x10000011
REQUEST_VERSIONPULL            = 0x00000012 # 版本库拉取
RESPONSE_VERSIONPULL           = 0x10000012
REQUEST_VERSIONADD             = 0x00000013 # 版本增加
RESPONSE_VERSIONADD            = 0x10000013
REQUEST_VERSIONSYNC            = 0x00000014 # 版本同步
RESPONSE_VERSIONSYNC           = 0x10000014
REQUEST_VERSIONQUERY           = 0x00000015 # 版本查询
RESPONSE_VERSIONQUERY          = 0x10000015
REQUEST_VERSIONDELETE          = 0x00000016 # 版本删除
RESPONSE_VERSIONDELETE         = 0x10000016
REQUEST_VERSIONROLLBACK        = 0x00000017 # 版本回退
RESPONSE_VERSIONROLLBACK       = 0x10000017

REQUEST_SC                     = 0x00000018 # 标准分类
RESPONSE_SC                    = 0x10000018

REQUEST_PULLSC                 = 0x00000019 # 拉取标准分类
RESPONSE_PULLSC                = 0x10000019
REQUEST_PUSHSC                 = 0x0000001A # 推送标准分类
RESPONSE_PUSHSC                = 0x1000001A

REQUEST_LOGIN                  = 0x0000001B # 登录
RESPONSE_LOGIN                 = 0x1000001B
REQUEST_SIGNUP                 = 0x0000001C # 注册
RESPONSE_SIGNUP                = 0x1000001C

REQUEST_DOWNLOAD               = 0x0000001D # 下载
RESPONSE_DOWNLOAD              = 0x1000001D

REQUEST_SEARCH_TEXT            = 0x0000001E # 按文本搜索接口
RESPONSE_SEARCH_TEXT           = 0x1000001E
REQUEST_SEARCH_FILE            = 0x0000001F # 按文件搜索接口
RESPONSE_SEARCH_FILE           = 0x1000001F
REQUEST_INTERFACE_INIT         = 0x00000020 # 内部接口初始化
RESPONSE_INTERFACE_INIT        = 0x10000020
REQUEST_DAMAGE_UPLOAD          = 0x00000021 # 毁伤上传接口
RESPONSE_DAMAGE_UPLOAD         = 0x10000021

ASSET_MODEL             = 0x1 << 0
ASSET_BVH               = 0x1 << 1
ASSET_EFFECT            = 0x1 << 2

# 模型大类定义 Model Category
MC_OUTFIT      = 0x0100   # 主战装备
MC_STAFF       = 0x0200   # 人员
MC_GROUND      = 0x0300   # 地物
MC_BUILDING    = 0x0400   # 建筑

def getModelCategory(category:int):
    if category == MC_OUTFIT: return 'outfit'
    elif category == MC_STAFF: return 'staff'
    elif category == MC_GROUND: return 'ground'
    else: return 'building'


protocalMap = {
    RESPONSE_ERROR: "RESPONSE_ERROR",
    REQUEST_SEARCHMODEL: "REQUEST_SEARCHMODEL",
    RESPONSE_SEARCHMODEL: "RESPONSE_SEARCHMODEL",
    REQUEST_UPLOADMODEL: "REQUEST_UPLOADMODEL",
    RESPONSE_UPLOADMODEL: "RESPONSE_UPLOADMODEL",
    REQUEST_SEARCHLABEL: "REQUEST_SEARCHLABEL",
    RESPONSE_SEARCHLABEL: "RESPONSE_SEARCHLABEL",
    REQUEST_SEARCHTYPE: "REQUEST_SEARCHTYPE",
    RESPONSE_SEARCHTYPE: "RESPONSE_SEARCHTYPE",
    REQUEST_TYPEINDEX: "REQUEST_TYPEINDEX",
    RESPONSE_TYPEINDEX: "RESPONSE_TYPEINDEX",
    REQUEST_LABELINDEX: "REQUEST_LABELINDEX",
    RESPONSE_LABELINDEX: "RESPONSE_LABELINDEX",
    REQUEST_MODELINDEX: "REQUEST_MODELINDEX",
    RESPONSE_MODELINDEX: "RESPONSE_MODELINDEX",
    REQUEST_PULLTYPE: "REQUEST_PULLTYPE",
    RESPONSE_PULLTYPE: "RESPONSE_PULLTYPE",
    REQUEST_PULLTAGS: "REQUEST_PULLTAGS",
    RESPONSE_PULLTAGS: "RESPONSE_PULLTAGS",
    REQUEST_PUSHTYPE: "REQUEST_PUSHTYPE",
    RESPONSE_PUSHTYPE: "RESPONSE_PUSHTYPE",
    REQUEST_PUSHTAGS: "REQUEST_PUSHTAGS",
    RESPONSE_PUSHTAGS: "RESPONSE_PUSHTAGS",
    REQUEST_UPLOADMODEL_SIMPLE: "REQUEST_UPLOADMODEL_SIMPLE",
    RESPONSE_UPLOADMODEL_SIMPLE: "RESPONSE_UPLOADMODEL_SIMPLE",
    REQUEST_SHOWTABLE: "REQUEST_SHOWTABLE",
    RESPONSE_SHOWTABLE: "RESPONSE_SHOWTABLE",
    REQUEST_INDEXPULL: "REQUEST_INDEXPULL",
    RESPONSE_INDEXPULL: "RESPONSE_INDEXPULL",
    REQUEST_INDEXPUSH: "REQUEST_INDEXPUSH",
    RESPONSE_INDEXPUSH: "RESPONSE_INDEXPUSH",
    REQUEST_VERSIONCREATE: "REQUEST_VERSIONCREATE",
    RESPONSE_VERSIONCREATE: "RESPONSE_VERSIONCREATE",
    REQUEST_VERSIONPULL: "REQUEST_VERSIONPULL",
    RESPONSE_VERSIONPULL: "RESPONSE_VERSIONPULL",
    REQUEST_VERSIONADD: "REQUEST_VERSIONADD",
    RESPONSE_VERSIONADD: "RESPONSE_VERSIONADD",
    REQUEST_VERSIONSYNC: "REQUEST_VERSIONSYNC",
    RESPONSE_VERSIONSYNC: "RESPONSE_VERSIONSYNC",
    REQUEST_VERSIONQUERY: "REQUEST_VERSIONQUERY",
    RESPONSE_VERSIONQUERY: "RESPONSE_VERSIONQUERY",
    REQUEST_VERSIONDELETE: "REQUEST_VERSIONDELETE",
    RESPONSE_VERSIONDELETE: "RESPONSE_VERSIONDELETE",
    REQUEST_VERSIONROLLBACK: "REQUEST_VERSIONROLLBACK",
    RESPONSE_VERSIONROLLBACK: "RESPONSE_VERSIONROLLBACK",
    REQUEST_SC: "REQUEST_SC",
    RESPONSE_SC: "RESPONSE_SC",
    REQUEST_PULLSC: "REQUEST_PULLSC",
    RESPONSE_PULLSC: "RESPONSE_PULLSC",
    REQUEST_PUSHSC: "REQUEST_PUSHSC",
    RESPONSE_PUSHSC: "RESPONSE_PUSHSC",
    REQUEST_LOGIN: "REQUEST_LOGIN",
    RESPONSE_LOGIN: "RESPONSE_LOGIN",
    REQUEST_SIGNUP: "REQUEST_SIGNUP",
    RESPONSE_SIGNUP: "RESPONSE_SIGNUP",
    REQUEST_DOWNLOAD: "REQUEST_DOWNLOAD",
    RESPONSE_DOWNLOAD: "RESPONSE_DOWNLOAD",
    REQUEST_SEARCH_TEXT: "REQUEST_SEARCH_TEXT",
    RESPONSE_SEARCH_TEXT: "RESPONSE_SEARCH_TEXT",
    REQUEST_SEARCH_FILE: "REQUEST_SEARCH_FILE",
    RESPONSE_SEARCH_FILE: "RESPONSE_SEARCH_FILE",
    REQUEST_INTERFACE_INIT: "REQUEST_INTERFACE_INIT",
    RESPONSE_INTERFACE_INIT: "RESPONSE_INTERFACE_INIT",
    REQUEST_DAMAGE_UPLOAD: "REQUEST_DAMAGE_UPLOAD",
    RESPONSE_DAMAGE_UPLOAD: "RESPONSE_DAMAGE_UPLOAD",
}

def protocalToStr(prot: int):
    return protocalMap[prot] if prot in protocalMap else "Unsupported Request or Response '%d'." % prot


# 用户权限定义 User Permission
UP_ADMIN       = 0x0001   # 管理员
UP_NORMAL      = 0x0002   # 普通

def getUserPermission(permission:int):
    if permission == UP_ADMIN: return 'admin'
    elif permission == UP_NORMAL: return 'normal'
    else: return 'normal'

# {
#     "type":REQUEST_SEARCHMODEL,
#     "state":"OK",
#     "titles":["category", "tag", "description", "similarity", "size"],
#     "values":[["airplane", "airplane", "a big airplane", "0.9", "196608"],],
# }
